let doctor_form=new Vue({
    el:"form",
    data:{
        departments:[],
        localdate:'2021-06-15',
        selectDepartment:"",
        file:""
    },
    methods:{
        loadInfo: function() {
            axios({
                url:"/portal/departmentOffice/medicaldepartment",
                method:"get",
            }).then(function(r) {
                var today = new Date();
                var yyyy = today.getFullYear();//获取当前年,月,日,时,分
                var MM = today.getMonth()+1;
                var dd = today.getDate();
                //如果月,日,时,分为个位数,就在前面加个0
                if (MM < 10) {
                    MM = "0" + MM;
                }
                if(dd<10){
                    dd="0"+dd;
                }
                //最终得到的时间格式
                doctor_form.localdate = yyyy + "-" + MM + "-" + dd ;
                doctor_form.departments=r.data;

            })
        },
        //获取并显示上传的图片
        getFile:function (event) {
            //获取发生事件input元素的第一个文件
            this.file=event.target.files[0];
            //创建一个fileReader对象
            var fileReader=new FileReader();
            //读取图片文件数据为DataUrl
            fileReader.readAsDataURL(this.file)
            //读取文件
            fileReader.onload=function(e) {
                //将这个url绑定到img元素的src属性
                $("#img").attr("src",e.target.result)
            }
            // console.log(this.file );
        },
        submitDoctor:function() {
            let username=$("#username").val();
            let password=$("#password").val();
            let name=$("#name").val();
            let email = $("#email" ).val();
            let phone = $("#phone" ).val();
            //这里本来用let声明,结果发现得到的值是undefined,于是就用了var
           var departmentId=$("#selectDepartment option:selected").attr("id");
           let bloodType=$("#bloodType option:selected").val();
           let birthday=$("#birthday").val();
           let introduce=$("#introduce").val();
           let gender=$(":radio:checked").val();
           let form=new FormData;
           // console.log("username",username )
           // console.log("password", password)
           // console.log("name", name)
           // console.log("email",email )
           // console.log("phone", phone)
           // console.log("departmentId",departmentId )
           console.log("bloodType", bloodType)
           // console.log("birthday",birthday )
           // console.log("picture", picture)
           // console.log("introduce", introduce)
           form.append("username",username);
           form.append("password",password);
           form.append("name",name);
           form.append("phone",phone);
           form.append("email",email);
           form.append("departmentId",departmentId);
           form.append("bloodType",bloodType);
           form.append("birthday",birthday);
           form.append("picture",this.file);
           form.append("introduce",introduce);
           form.append("gender",gender);
           axios({
               url : "/portal/doctors/add_doctor",
               method:"post",
               data:form
           }).then(function(r) {
               alert(r.data)
               if(r.data=="添加成功"){
                   location.reload();
               }
           })

        },
        clearAll:function () {
            console.log("清空所有" )
            //清空所有已填信息
                $(".info").val("");
            $("#img").attr("src","../../assets/img/dashboard/headmodel.jpg")
            doctor_form.file=""
            //重新获取当前时间
            this.loadInfo();
        }
    },
    created:function () {
     this.loadInfo();
    }
})